<template>
  <div class="app-container">
    <el-row>
      <el-col>
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
          label-width="60px" v-if="!isOpen">
<!--          <el-form-item label="编号" prop="productNo">-->
<!--            <el-input v-model="queryParams.productNo" placeholder="请输入产品编号" clearable-->
<!--              @keyup.enter.native="handleQuery" />-->
<!--          </el-form-item>-->
          <el-form-item label="产品名称" prop="productName">
            <el-input v-model="queryParams.productName" placeholder="请输入产品名称" clearable
              @keyup.enter.native="handleQuery" />
          </el-form-item>
          <el-form-item label="状态" prop="productStatus">
            <el-select v-model="queryParams.productStatus" placeholder="请选择产品状态" clearable>
              <el-option label="未上架" value="未上架" />
              <el-option label="已上架" value="已上架" />
              <el-option label="已下架" value="已下架" />
            </el-select>
          </el-form-item>
          <el-form-item label="公布" prop="examineStatus">
            <el-select v-model="queryParams.examineStatus" placeholder="请选择审核状态" clearable>
              <el-option label="未审核" value="未审核" />
              <el-option label="待审核" value="待审核" />
              <el-option label="已发布" value="已发布" />
              <el-option label="审核未通过" value="审核未通过" />
              <el-option label="停用" value="停用" />
            </el-select>
          </el-form-item>
          <el-form-item label="细分类别" prop="productSegmentationClassification">
            <el-select v-model="queryParams.productSegmentationClassification" placeholder="请选择细分类别" >
              <el-option
                v-for="dict in dict.type.product_segmentation_classification"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        <el-row>
          <el-col :span="24">
            <el-form-item
              size="mini"
              label="产品类别"
              prop="productType"
            >
              <div class="manager-tags">
      <span
        v-for="manager in managerList"
        :key="manager.dictValue"
        :class="['manager-tag', queryParams.productType === manager.dictValue ? 'active' : '']"
        @click="handleManagerSelect(manager)"
      >
        {{ manager.dictLabel }}
      </span>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
        </el-form>
        <el-row :gutter="10" class="mb8" v-if="!isOpen">
          <el-col :span="1.5">
            <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
              v-if="orgId !== 100">新增</el-button>
          </el-col>
<!--          <el-col :span="1.5">-->
<!--            <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"-->
<!--              v-if="!isOpen">导出</el-button>-->
<!--          </el-col>-->
          <el-col :span="1.5">
            <el-button type="info" plain icon="el-icon-upload2" size="mini" @click="handleImport"
              v-if="orgId !== 100">导入</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="success" plain icon="el-icon-plus" size="mini" :disabled="multiple" @click="handleListing"
              v-if="orgId !== 100">上架</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="warning" plain icon="el-icon-remove" size="mini" :disabled="multiple"
              @click="handleShelves" v-if="orgId !== 100">下架</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" plain icon="el-icon-star-off" size="mini" :disabled="multiple"
              @click="handleRelease" v-if="orgId !== 100">发布</el-button>
          </el-col>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
        </el-row>
        <div style="width: 100%;height: 90vh;overflow:auto; margin-bottom: 30%;padding-bottom: 18%;position: relative;">
        <el-table :row-style="{ height: '30px' }" :cell-style="{ padding: '0px' }" :height="500" border
          v-loading="loading" :data="qualificationList" @selection-change="handleSelectionChange" highlight-current-row>
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="序" type="index" :index="indexMethod" width="40" align="left"/>
          <el-table-column label="发布时间" align="center" prop="releaseTime" width="85px" v-if="columns[0].visible">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.releaseTime, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="产品类别" align="center" prop="productType" :show-overflow-tooltip="true"
            v-if="columns[1].visible">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.product_type" :value="scope.row.productType" />
            </template>
          </el-table-column>
          <el-table-column label="状态" align="center" prop="productStatus" width="70px" :show-overflow-tooltip="true"
            v-if="columns[8].visible" />
          <el-table-column label="公布" align="center" prop="examineStatus" width="70px"
            :show-overflow-tooltip="true" />
          <el-table-column label="编号" align="center" prop="productNo" width="70px" :show-overflow-tooltip="true"
            v-if="columns[2].visible" />
          <el-table-column label="产品名称" align="left" prop="productName" :show-overflow-tooltip="true" width="200px"
            v-if="columns[3].visible" />
<!--          <el-table-column label="服务机构" align="center" prop="organizationName" :show-overflow-tooltip="true" />-->
<!--          <el-table-column label="产品介绍" align="center" prop="productRemark">-->
<!--            <template slot-scope="scope">-->
<!--              <div class="truncate-text" :title="formatRemark(scope.row.productRemark).title" v-if="scope.row.productRemark!==null">-->
<!--                {{ scope.row.productRemark.substring(0, 4) }}{{ scope.row.productRemark.length > 10 ? '...' : '' }}-->
<!--              </div>-->
<!--            </template>-->
<!--          </el-table-column>-->
          <el-table-column label="产品规格" prop="productSpecs" width="350px" align="left" :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <div class="truncate-text" style="text-align: left;"
                   :title="formatRemark(scope.row.productSpecs).title"
                   v-if="scope.row.productSpecs !== null">
                {{ scope.row.productSpecs.length > 40 ? scope.row.productSpecs.substring(0, 25) + '...' : scope.row.productSpecs }}
              </div>
            </template>
          </el-table-column>
<!--          <el-table-column label="创建人" align="center" prop="userName" :show-overflow-tooltip="true" width="100"-->
<!--            v-if="columns[9].visible" />-->
          <el-table-column label="创建时间" align="center" prop="creationTime" width="100px" :show-overflow-tooltip="true"
            v-if="columns[10].visible">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.creationTime, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="执行文件" align="center" prop="exeStandard">
            <template slot-scope="scope">
              <el-button @click.stop="handlePictureCardPreview(scope.row.exeStandard, exeStandardCode)" size="small" class="el-icon-document"
                type="text"></el-button>
            </template>
          </el-table-column>
          <el-table-column label="样板" align="center" prop="template">
            <template slot-scope="scope">
              <el-button @click.stop="handlePictureCardPreview(scope.row.template, businessCode)" size="small" class="el-icon-document"
                type="text"></el-button>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="190px" fixed="right"
            v-if="!isOpen">
            <template slot-scope="scope">
              <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row, scope.$index)" v-if="orgId!==100"
                         :disabled=" orgId === 100 || scope.row.productStatus === '已上架'"  title="修改"></el-button>
              <el-button size="mini" type="text" icon="el-icon-s-grid" @click="handleLvli(scope.row)"  title="履历"></el-button>
              <el-button size="mini" type="text" icon="el-icon-magic-stick"  v-if="orgId===100"
                @click="handleExamine(scope.row, scope.$index)" :disabled="orgId !== 100 || scope.row.examineStatus !== '待审核'"  title="审核"></el-button>
              <el-button size="mini" type="text" icon="el-icon-view" @click="handleSelect(scope.row, scope.$index)"  title="查看"></el-button>
              <el-button size="mini" type="text" icon="el-icon-remove-outline" @click="handleRevoke(scope.row)" v-if="orgId!==100"
                         :disabled="orgId === 100 || !((scope.row.examineStatus === '待审核' && scope.row.productStatus === '已上架'))"  title="撤销">
              </el-button>
              <el-button size="mini" type="text" icon="el-icon-switch-button" @click="handleDeactivate(scope.row)" v-if="orgId!==100"
                         :disabled="scope.row.examineStatus!=='已发布'"  title="停用">
              </el-button>
              <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-tooltip="'删除资质'" v-if="orgId!==100"
                :disabled="!((scope.row.examineStatus==='未审核' && scope.row.productStatus==='未上架') ||(scope.row.examineStatus==='未审核' && scope.row.productStatus==='已下架'))"  title="删除"></el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize" @pagination="getList" />
        </div>
      </el-col>
    </el-row>
    <!-- 添加或修改资质产品管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body @close="cancel">
      <div v-if="addSign !== 0">
        <el-descriptions title="">
          <el-descriptions-item label="NO">
            <el-tag size="medium">{{ index }}</el-tag>
          </el-descriptions-item>
        </el-descriptions>
      </div>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px" :inline="true">
        <el-form-item label="创建时间" prop="creationTime">
          <el-date-picker clearable v-model="form.creationTime" type="date" value-format="yyyy-MM-dd"
                          placeholder="请选择时间" id="inp" disabled="true">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="产品类别" prop="productType" label-width="69px">
          <el-select v-model="form.productType" placeholder="请选择产品类别" id="inp" :disabled="OnlyRead" @change="handleProductTypeChange">
            <el-option v-for="dict in dict.type.product_type" :key="dict.value" :label="dict.label"
              :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="产品名称" prop="productName">
          <el-input v-model="form.productName" placeholder="请输入产品名称" maxlength="20"
                    show-word-limit
            :style="{ width: addSign === 1 || addSign === 2 ? '202.5px' : '150.5px' }" :disabled="OnlyRead">
          </el-input>
          <el-button v-if="addSign !== 1 && addSign !== 2" type="primary" size="mini" @click="handleChange" :disabled="OnlyRead"
            style="height: 35px">选择</el-button>
        </el-form-item>
        <el-form-item label="编号" prop="productNo">
          <el-input  v-model="form.productNo" placeholder="请选择产品类别生成" id="inp"  :disabled="OnlyRead"/>
        </el-form-item>
        <el-form-item label="统一编号" prop="unifiedNo" v-if="orgId===100">
          <el-input  v-model="form.unifiedNo" placeholder="请输入统一编号" id="inp" disabled="true"  :disabled="addStatus !== 3"/>
        </el-form-item>
        <el-form-item label="发布时间" prop="releaseTime">
          <el-date-picker clearable v-model="form.releaseTime" type="date" value-format="yyyy-MM-dd" placeholder="请选择时间"
                          id="inp" :disabled="form.id!==null?OnlyRead:false">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="细分分类" label-width="69px">
          <el-select v-model="form.productSegmentationClassification" placeholder="请选择产品类别" id="inp" :disabled="OnlyRead" >
            <el-option v-for="dict in dict.type.product_segmentation_classification" :key="dict.value" :label="dict.label"
                       :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="产品规格" prop="productSpecs">
          <el-input v-model="form.productSpecs" type="textarea" placeholder="请输入内容" style="width: 500px"
                    :disabled="form.id!==null?OnlyRead:false" />
        </el-form-item>
        <el-form-item label="产品介绍" prop="productRemark">
          <el-input v-model="form.productRemark" type="textarea" placeholder="请输入内容" style="width: 500px"
            :disabled="form.id!==null?OnlyRead:false" />
        </el-form-item>
        <el-form-item  label="供应商产品" prop="supplierProductList" >
          <div class="supplier-product-container">
            <el-button type="primary" size="mini" @click="openSupplierDialog" :disabled="form.id!==null?OnlyRead:false">新增</el-button>
            <el-table
              v-if="form.supplierProductList && form.supplierProductList.length > 0"
              :data="form.supplierProductList"
              border
              size="mini"
              style="width: 100%; margin-top: 8px;"
            >
              <el-table-column label="序号" type="index" width="50" align="center"></el-table-column>
              <el-table-column label="产品名称" prop="productName" :show-overflow-tooltip="true"></el-table-column>
              <el-table-column label="供应商名称" prop="enterpriseName" :show-overflow-tooltip="true"></el-table-column>
              <el-table-column label="操作" width="60" align="center" v-if="!OnlyRead">
                <template slot-scope="scope">
                  <el-button type="text" icon="el-icon-delete" @click="removeSupplierProduct(scope.$index)"></el-button>
                </template>
              </el-table-column>
            </el-table>
            <div v-else-if="!OnlyRead" style="color: #909399; font-size: 14px; margin-top: 8px; text-align: center;">
              请点击新增按钮添加供应商产品
            </div>
          </div>
        </el-form-item>
        <el-form-item label="服务机构" v-if="addSign === 3 || addSign === 2">
          <el-input v-model="form.organizationName" id="inp" disabled="true" />
        </el-form-item>
        <el-form-item label="审核状态" prop="examineStatus" label-width="110px"
          v-if="addSign !== 0 && addSign !== 1 && ((form.examineStatus === '已发布' || form.examineStatus === '待审核' || form.examineStatus==='审核未通过'))">
          <el-radio-group v-model="form.examineStatus" :disabled="addStatus !== 3">
            <el-radio label="已发布">审核通过</el-radio>
            <el-radio label="审核未通过">审核不通过</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="审核意见" prop="endReason"
          v-if="form.examineStatus === '审核未通过' && addSign !== 0 && addSign !== 1" label-width="80px">
          <el-input v-model="form.endReason" type="textarea" placeholder="请输入审核意见" style="width: 440px" maxlength="300"
            show-word-limit :disabled="addStatus !== 3" />
        </el-form-item>
        <el-form-item label="执行标准" prop="exeStandard">
          <file-view v-if="isUpload" :type="typeSelect" :businessId="form.exeStandard" :businessCode="exeStandardCode"
            @change="getFile" style="width: 500px"></file-view>
        </el-form-item>
        <el-form-item label="样板" prop="template">
          <file-view v-if="isUpload" :type="typeSelect" :businessId="form.template" :businessCode="businessCode"
            @change="getFile" style="width: 500px"></file-view>
        </el-form-item>
        <el-form-item label="产品手册" prop="productManual">
          <file-view v-if="isUpload" :type="typeSelect" :businessId="form.productManual" :businessCode="productManual"
                     @change="getFile" style="width: 500px"></file-view>
        </el-form-item>
        <el-form-item label="创建人" prop="userName">
          <el-input v-model="form.userName" id="inp" disabled="true" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" style="display: flex; justify-content: center; align-items: center;"
        v-if="addSign !== 2">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>
    <!--    履历对话框-->
    <el-dialog title="履历列表" :visible.sync="resumeOpen" width="1500px" @close="resetReusumeClose()">
      <el-row>
        <el-col :span="24">
          <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
              <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAddLvli">新增</el-button>
            </el-col>
          </el-row>
          <el-table :row-style="{ height: '30px' }" :cell-style="{ padding: '0px' }" v-loading="loading"
            :data="ResumeList">
            <el-table-column label="序号" type="index" :index="indexMethod" />
            <el-table-column label="更新时间" align="center" prop="operateTime" width="180">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.operateTime, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>

            <el-table-column label="更新内容" align="center" prop="operateContent" :show-overflow-tooltip="true">
              <template slot-scope="scope">
                <div class="ellipsis-cell" :title="scope.row.operateContent">{{ scope.row.operateContent }}</div>
              </template>
            </el-table-column>
            <el-table-column label="状态" align="center" prop="status" :show-overflow-tooltip="true">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.qualification_resume_status" :value="scope.row.status" />
              </template>
            </el-table-column>
            <el-table-column label="更新人" align="center" prop="operateName" :show-overflow-tooltip="true" />
            <el-table-column label="审批人" align="center" prop="approveName" :show-overflow-tooltip="true" />
            <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true">
              <template slot-scope="scope">
                <div class="ellipsis-cell" :title="scope.row.remark">{{ scope.row.remark }}</div>
              </template>
            </el-table-column>
            <el-table-column label="创建人" align="center" prop="createName" :show-overflow-tooltip="true" width="100" />
            <el-table-column label="创建时间" align="center" prop="creationTime" width="180" :show-overflow-tooltip="true">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.creationTime, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="附件" align="center" prop="uploadFile">
              <template slot-scope="scope">
                <el-button @click.stop="handlePictureCardPreviewResume(scope.row.uploadFile)" size="small"
                  type="text">附件</el-button>
              </template>
            </el-table-column>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="80">
              <template slot-scope="scope">
                <el-button size="mini" type="text" icon="el-icon-edit"
                  @click="handleUpdateLvli(scope.row, scope.$index)"  title="修改"></el-button>
              </template>
            </el-table-column>
          </el-table>
          <pagination v-show="Resumetotal > 0" :total="Resumetotal" :page.sync="ResumeParams.pageNum"
            :limit.sync="ResumeParams.pageSize" @pagination="getResumeList" />
        </el-col>
      </el-row>
    </el-dialog>
    <!--    履历对话框结束-->
    <!-- 添加或修改资质产品履历对话框 -->
    <el-dialog :title="resumeTitle" :visible.sync="openResumeWX" width="720px" append-to-body>
      <div v-if="addSign === 1">
        <el-descriptions title="">
          <el-descriptions-item label="序号">
            <el-tag size="medium">{{ index }}</el-tag>
          </el-descriptions-item>
        </el-descriptions>
      </div>
      <el-form ref="formResume" :model="formResume" label-width="80px" :inline="true" :rules="resumeRules">
        <el-form-item label="更新时间" prop="operateTime">
          <el-date-picker clearable v-model="formResume.operateTime" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择更新时间" id="inp">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="更新人" prop="operateName">
          <el-input v-model="formResume.operateName" placeholder="请输入更新人" id="inp" @focus="selectOpen('1')" />
        </el-form-item>

        <el-form-item label="审批人" prop="approveName">
          <el-input v-model="formResume.approveName" placeholder="请输入审批人" id="inp" @focus="selectOpen('3')" />
        </el-form-item>
        <el-form-item label="状态" label-width="100px">
          <el-select v-model="formResume.status" placeholder="请选择状态" style="width: 202.5px">
            <el-option v-for="dict in dict.type.qualification_resume_status" :key="dict.value" :label="dict.label"
              :value="dict.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="创建人" prop="createName" >
          <el-input v-model="formResume.createName" placeholder="请输入创建人" style="width: 202.5px;" disabled="true" />
        </el-form-item>
        <el-form-item label="创建时间" prop="creationTime" label-width="100px">
          <el-date-picker clearable v-model="formResume.creationTime" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择创建时间" id="inp" disabled="true">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="更新内容" prop="operateContent">
          <el-input v-model="formResume.operateContent" type="textarea" placeholder="请输入内容" style="width: 530px" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="formResume.remark" type="textarea" placeholder="请输入内容" style="width: 530px" />
        </el-form-item>
        <el-form-item label="附件" prop="uploadFile">
          <file-view v-if="showResume" :limit="1" :type="typeSelect" :businessId="formResume.uploadFile"
            :businessCode="businessCode"></file-view>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormResume">确 定</el-button>
        <el-button @click="cancelResume">关 闭</el-button>
      </div>
    </el-dialog>
    <!--      新增和修改履历对话框结束-->

    <!-- 导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload ref="upload" :limit="1" accept=".xlsx, .xls" :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport" :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress" :on-success="handleFileSuccess" :auto-upload="false" drag>
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;"
            @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">关 闭</el-button>
      </div>
    </el-dialog>
    <select-user ref="select" :type="userType" :sign="Resign" @ok="selectUser"></select-user>
    <!--   履历 附件展示对话框-->
    <el-dialog title="查看附件" :visible.sync="openFileList" width="500px" append-to-body v-if="openFileList">
      <UploadFile :upload-id="uploadId" :business-code="UploadCode"></UploadFile>
    </el-dialog>
    <!--   履历 附件展示对话框-->
    <el-dialog title="查看附件" :visible.sync="resumeFileList" width="500px" append-to-body v-if="resumeFileList">
      <UploadFile :upload-id="uploadId" :business-code="businessCode"></UploadFile>
    </el-dialog>
    <!-- 选择对话框开始 -->
    <el-dialog title="选择主营产品" :visible.sync="changeOpen" width="1000px" append-to-body @close="cancelChange">
      <change @product="changeProduct" @closeProduct="closeProduct" v-if="isChange"></change>
    </el-dialog>
    <!-- 选择对话框结束 -->
    <!-- 供应商产品对话框 -->
    <el-dialog title="选择供应商产品" :visible.sync="supplierDialogVisible" width="70%" append-to-body @close="handleSupplierDialogClose" :close-on-click-modal="false">
      <supplier-qualification :bId="form.enterpriseId" @selectProduct="handleSelectProduct" ref="supplierQualification"></supplier-qualification>
    </el-dialog>
  </div>
</template>

<script>
import { listQualification, getQualification, delQualification, addQualification, updateQualification, approveStatus, releaseStatus, examine, listQualificationAll, revokeNot,getNo,apply } from "@/api/qualificationInfo/qualification";
import FileView from "@/components/FileView/index"
import { listResume, getResume, delResume, addResume, updateResume } from "@/api/qualificationInfo/Resume";
import { getToken } from "@/utils/auth";
import SelectUser from "../system/role/selectUser.vue";
import MainType from "@/components/MainType/index"
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import { listType } from "@/api/maintype/type";
import UploadFile from "../upload/index.vue";
import change from "./change.vue";
import { queryFile, fileRemove } from "@/api/system/file";
import {getDicts} from "@/api/system/dict/data";
import supplierQualification from "./supplierQualification.vue";
export default {
  name: "Qualification",
  dicts: ['product_type', 'product_status', 'customer_industry', 'administrative_area', 'qualification_resume_status','product_segmentation_classification'],
  components: { UploadFile, FileView, SelectUser, MainType, Treeselect, change, supplierQualification },
  props: {
    orgId: {
      type: Number,
      default: 0
    },
    isOpen: {
      type: Boolean,
      default: false
    },
  },
  data() {
    var validateRadio = (rule, value, callback) => {
      if (value) {
        // 当值为0的时候当做没选择
        if (value === '待审核') {
          callback(new Error('请选择审核结果'))
        } else {
          callback();
        }
      } else {
        callback(new Error('请选择审核结果'));
      }
    };
    return {
      orgId: this.$store.state.user.info.orgId,
      companyType: this.$store.state.user.info.companyType,
      productId: null,//父传子使用，高亮展示
      classRead: false,
      //主类别
      typeCode: 'qualification',
      isChange: true,
      typeCodeResume: 'qualification_resume',
      // 遮罩层
      loading: true,
      managerList:[],
       loadingEnter: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      //修改页面中的序号展示
      index: 0,
      addSign: 0,
      OnlyRead: false,//只读
      // 显示搜索条件
      showSearch: true,
      //附件标志位
      isUpload: false,
      //选择标志位
      changeOpen: false,
      examineList: [],
      productStatusList:[],
      // 总条数
      total: 0,
      //判断是否用自定义的下拉框还是数据字典的下拉框
      addStatus: 1,
      // 资质产品管理表格数据
      qualificationList: [],
      // 企业信息表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //弹出框选择，默认为0
      typeSelect: 0,
      businessCode: 'qualification',
      exeStandardCode: 'exeStandard',
      productManual:'productManual',
      //统计查看样板和执行标准的附件
      UploadCode: '',
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 15,
        productType: null,
        productNo: null,
        productName: null,
        productStatus: null,
        examineStatus: null,
        classificationId: null,
        organizationName: null,
        productSegmentationClassification: null,
      },
      //产品状态
      op: [{
        value: 1,
        label: '上架'
      }],
      dialogImageUrl: '',
      ImgDig: false,
      //主分类
      options: null,
      //主分类履历
      optionsResume: null,
      // 履历查询参数
      ResumeParams: {
        pageNum: 1,
        pageSize: 15,
        qualificationId: null,
        classificationId: null
      },
      //履历对话框标志
      resumeOpen: false,
      //附件对话框
      openFileList: false,
      resumeFileList: false,
      uploadId: null,
      //履历数据列表
      ResumeList: [],
      //履历总数
      Resumetotal: null,
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/qualificationInfo/qualification/importData"
      },
      //第二层的查询条件
      queryParamsTwo: {
        pageNum: 1,
        pageSize: 15,
        enterpriseName: null,
        administrativeArea: null,
        enterpriseLabel: null,
        industry: null,
      },
      //外协id
      enterId: [],
      //外协名称集合
      enterName: [],
      // 表单参数
      form: {
        id: null,
        productType: null,
        productNo: null,
        productName: null,
        productPrice: null,
        productSellPrice: null,
        productStatus: null,
        enterpriseId: null,
        enters: null,
        productRemark: null,
        exeStandard: null,
        template: null,
        operateId: null,
        departmentId: null,
        organizationId: null,
        departmentName: null,
        organizationName: null,
        creationTime: null,
        operateTime: null,
        createId: null,
        selectUrl: null,
        userName: null,
        releaseTime: null,
        approve: null,
        classificationId: null,
        uploadFile: null,
        isChange: null,
        examineStatus: null,
        endReason: null,
        productSpecs: null,
        productManual: null,
        unifiedNo: null,
        productSegmentationClassification: null,
        supplierProduct: null,
        supplierProductId: null,
        supplierProductList: []
      },
      // 表单校验
      rules: {
        productType: [
          { required: true, message: '请选择产品类别', trigger: 'change' }
        ],
        productNo: [
          { required: true, message: '请输入编号', trigger: 'blur' }
        ],
        productName: [
          { required: true, message: '请输入产品名称', trigger: 'blur' }
        ],
        certificateInstitution: [
          { required: true, message: '请输入发证机构', trigger: 'blur' }
        ],
        productRemark: [
          { required: true, message: '请输入产品介绍', trigger: 'blur' }
        ],
        releaseTime: [
          { required: true, message: '请选择发布时间', trigger: 'change' }
        ],
        template: [
          { required: true, message: '请上传样板', trigger: 'change' }
        ],
        examineStatus: [
          { required: true, validator: validateRadio, trigger: "change" },
        ],
        endReason: [
          { required: true, message: '请输入终止原因', trigger: 'blur', when: (data) => data.sendType === 'termination' },
        ],
        unifiedNo:[
          { required: true, message: '请输入统一编号', trigger: 'blur' }
        ],
        productSpecs:[
          { required: true, message: '请输入产品规格', trigger: 'blur' }
        ]
      },
      resumeRules: {
        operateTime: [
          { required: true, message: '请选择更新时间', trigger: 'change' }
        ],
        operateName: [
          { required: true, message: '请选择更新人', trigger: 'change' }
        ],
        approveName: [
          { required: true, message: '请选择审批人', trigger: 'change' }
        ],
        operateContent: [
          { required: true, message: '请输入更新内容', trigger: 'blur' }
        ]
      },
      // 列信息
      columns: [
        { key: 0, label: `发布时间`, visible: true },
        { key: 1, label: `产品类别`, visible: true },
        { key: 2, label: `产品编号`, visible: true },
        { key: 3, label: `产品名称`, visible: true },
        { key: 4, label: `定价范围`, visible: true },
        { key: 5, label: `发证机构`, visible: true },
        { key: 6, label: `查询网址`, visible: true },
        { key: 7, label: `产品介绍`, visible: true },
        { key: 8, label: `产品状态`, visible: true },
        { key: 9, label: `创建人`, visible: true },
        { key: 10, label: `创建时间`, visible: true },
      ],
      //履历对话框标题
      resumeTitle: null,
      //履历新增或删除标志
      openResumeWX: false,
      formResume: {},
      userType: "1",
      Resign: '1',
      show: null,
      //控制履历附件
      showResume: false,
      // 供应商产品对话框
      supplierDialogVisible: false
    };
  },
  created() {
    this.getDicts();
    console.log(this.$store.state.user)
    this.orgId=this.$store.state.user.info.orgId;
    this.getList();
    this.listTypeResume();
  },
  methods: {
    //获取树节点数据
    listTypeResume() {
      listType({ typeCode: 'qualification_resume' }).then(res => {
        this.optionsResume = res.data;
      })
    },
    getDicts() {
      getDicts('product_type').then(res => {
        this.managerList = res.data;
      });
    },
    //点击接收方文本域,弹出选择当前用户在企业管理中的企业信息
    handleTextAreaFocus() {
      this.openUser = true;
    },
    handleManagerSelect(manager) {
      if (this.queryParams.productType === manager.dictValue) {
        this.queryParams.productType = null; // 再次点击取消选择
      } else {
        this.queryParams.productType = manager.dictValue;
      }
      this.handleQuery(); // 触发搜索
    },
    /** 查询资质产品管理列表 */
    getList() {
      this.loading = true;
      if (this.$store.state.user.info.orgId !== 100) {
        listQualification(this.queryParams).then(response => {
          console.log(response.rows)
          this.qualificationList = response.rows;
          this.total = response.total;
          console.log(this.total)
          this.loading = false;
        });
      } else {
        listQualificationAll(this.queryParams).then(response => {
          console.log(response.rows)
          this.qualificationList = response.rows;
          this.total = response.total;
          console.log(this.total)
          this.loading = false;
        })
      }
    },
    handleProductTypeChange(value){
      getNo(value,this.form.id).then(res=>{
        this.form.productNo=res;
      })
    },
    //点击获取主类别树节点
    getNode(data) {
      if (data.parentId != '00000000-0000-0000-0000-000000000000') {
        this.queryParams.classificationId = data.id
      } else {
        this.queryParams.classificationId = null;
      }
      this.getList()
    },
    //履历点击获取主类别树节点
    //履历:树点击事件
    getNodeResume(data) {
      if (data.parentId != '00000000-0000-0000-0000-000000000000') {
        this.ResumeParams.classificationId = data.id
      } else {
        this.ResumeParams.classificationId = null;
      }
      this.getResumeList();
    },
    formatRemark(remark) {
      const displayedText = remark.length > 50 ? remark.substring(0, 80) + '...' : remark;
      const title = remark.length > 50 ? remark.substring(0, 80) + '...' : remark;
      return { displayedText, title };
    },
    // 取消按钮
    cancel() {
      this.$refs.form.resetFields();
      this.isUpload = false;
      this.OnlyRead = false;
      this.open = false;
      this.classRead = false;
      this.reset();
    },
    cancelChange() {
      this.isUpload = true;
      this.changeOpen = false;
    },
    //序号展示
    indexMethod(index) {
      return index + 1;
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        productType: null,
        productNo: null,
        productName: null,
        productPrice: null,
        productSellPrice: null,
        productStatus: null,
        enterpriseId: null,
        enters: null,
        productRemark: null,
        exeStandard: null,
        template: null,
        operateId: null,
        departmentId: null,
        organizationId: null,
        departmentName: null,
        organizationName: null,
        creationTime: null,
        operateTime: null,
        createId: null,
        selectUrl: null,
        userName: null,
        releaseTime: null,
        approve: null,
        classificationId: null,
        uploadFile: null,
        isChange: null,
        examineStatus: null,
        endReason: null,
        productSpecs: null,
        productManual: null,
        unifiedNo: null,
        productSegmentationClassification: null,
        supplierProduct: null,
        supplierProductId: null,
        supplierProductList: []
      }
      // this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "用户导入";
      this.upload.open = true;
    },
    //上架
    handleListing() {
      const result = this.productStatusList.some(item => item.includes("已上架"));
     if (result){
       this.$message.error("不能重复上架已上架的产品");
     }else {
       approveStatus(this.ids, "已上架").then(response => {
         this.$modal.msgSuccess("上架成功");
         this.getList();
       })
     }
    },
    //下架
    handleShelves() {
      const result = this.examineList.some(item => item.includes("已发布"));
      const status = this.productStatusList.some(item => item.includes("未上架"));
      const tingyong = this.examineList.some(item => item.includes("停用"));
      if (result || status) {
        this.$message.error("不能下架未上架的产品以及已发布的产品");
      }else if (tingyong){
        this.$message.error("停用状态不可进行下架操作！");
      } else {
        approveStatus(this.ids, "已下架").then(response => {
          this.$modal.msgSuccess("下架成功");
          this.getList();
        })
      }
    },
    //发布
    handleRelease() {
      const result = this.productStatusList.some(item => item === '已上架');
      const status=this.examineList.some(item=>item==='待审核' || item==='已发布')
      const tingyong = this.examineList.some(item => item === '停用');
      if (!result) {
        this.$message.error("需先上架产品才允许发布！")
      }else if (status){
        this.$message.error("不允许重复发布已发布过的产品！")
      }else if (tingyong){
        this.$message.error("停用状态不可发布！！！");
      }
      else {
        releaseStatus(this.ids).then(res => {
          this.$modal.msgSuccess("发布成功");
          this.getList();
        })
      }
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('/qualificationInfo/qualification/importTemplate', {
      }, `资质产品信息导出.xlsx`)
    },
    // 履历表单重置
    resetResume() {
      this.formResume = {
        id: null,
        qualificationId: null,
        operateTime: null,
        operateContent: null,
        status: null,
        operateId: null,
        approveId: null,
        remark: null,
        createId: null,
        creationTime: null,
        uploadFile: null,
        createName: null,
        approveName: null,
        operateName: null,
      };
      this.resetForm("formResume");
    },
    //履历对话框
    handleLvli(row) {
      const id = row.id
      this.ResumeParams.qualificationId = row.id;
      this.getResumeList();
      this.resumeOpen = true;
    },
    //审核
    handleExamine(row, index) {
      this.reset();
      const id = row.id || this.ids
      getQualification(id).then(response => {
        this.form = response.data;
        this.addStatus = 3;
        this.addSign = 3;
        this.index = index + 1;
        this.typeSelect = 2;
        this.form.endReason=null;
        this.OnlyRead = true;
        this.isUpload = true;
        this.open = true;
        this.title = "审核主营产品信息";
      });
    },
    //查看
    handleSelect(row, index) {
      this.reset();
      const id = row.id || this.ids
      getQualification(id).then(response => {
        this.form = response.data;
        this.addStatus = 2;
        this.addSign = 2;
        this.index = index + 1;
        this.typeSelect = 2;
        this.OnlyRead = true;
        if (this.companyType === '2') {
          //说明是园区
          this.classRead = true;
        }
        this.isUpload = true;
        this.open = true;
        this.title = "查看主营产品信息";
      });
    },
    //删除
    handleDelete(row) {
      this.$confirm('此操作将删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        delQualification(row.id).then(res => {
          this.$message.success("删除成功");
          this.getList();
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });
      });
    },
    //撤销审核
    handleRevoke(row) {
      this.$confirm('此操作将撤销审核, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        revokeNot(row.id).then(res => {
          if (res.code === 200) {
            this.$message.success("撤销成功");
            this.getList();
          } else {
            this.$message.error("撤销失败");
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });
      });
    },
    //停用
    handleDeactivate(row){
      this.$confirm('此操作将停用该产品, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        apply(row.id).then(res=>{
          if (res.code === 200) {
            this.$message.success("停用成功");
            this.getList();
          } else {
            this.$message.error("停用失败");
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });
      });
    },
    //启用
    handleEnable(row){
      this.$confirm('此操作重新启用该产品, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        apply(row.id).then(res=>{
          if (res.code === 200) {
            this.$message.success("启用成功");
            this.getList();
          } else {
            this.$message.error("启用成功");
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });
      });
    },
    //关闭履历，刷新树节点
    resetReusumeClose() {
      this.ResumeParams.classificationId = null
      console.log(this.ResumeParams)
    },
    //履历列表
    getResumeList() {

      listResume(this.ResumeParams).then(response => {
        this.ResumeList = response.rows;
        console.log(this.ResumeList)
        this.Resumetotal = response.total;
        this.loading = false;
      });
    },
    /** 新增履历操作 */
    handleAddLvli() {
      this.resetResume();
      this.formResume.qualificationId = this.ResumeParams.qualificationId;
      this.formResume.createName = this.$store.state.user.name;
      this.formResume.creationTime = new Date();
      this.formResume.uploadFile = new Date().getTime();
      this.formResume.classificationId = '650c44e1-b575-4b62-9d54-1ba9d1e8abb7'

      this.addSign = 0;
      this.typeSelect = 0;
      this.showResume = true;
      this.listTypeResume();
      this.openResumeWX = true;
      this.resumeTitle = "添加";
    },
    /** 修改履历操作 */
    handleUpdateLvli(row, index) {
      this.reset();
      console.log(this.formResume)
      const id = row.id
      this.index = index + 1
      this.typeSelect = 1;
      this.addSign = 1;
      getResume(id).then(response => {
        this.formResume = response.data;
        this.openResumeWX = true;
        this.listTypeResume();
        this.resumeTitle = "修改资质产品履历";
        this.showResume = true;
      });
    },
    /** 提交履历按钮 */
    submitFormResume() {
      this.$refs["formResume"].validate(valid => {
        if (valid) {
          if (this.formResume.id != null) {
            updateResume(this.formResume).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.openResumeWX = false;
              this.showResume = false;
              this.getResumeList();
            });
          } else {
            console.log(this.formResume)
            addResume(this.formResume).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.openResumeWX = false;
              this.showResume = false;
              this.getResumeList();
            });
          }
        }
      });
    },
    //取消履历
    cancelResume() {
      this.openResumeWX = false;
      this.showResume = false;
      this.resetResume();
    },
    //点击选择用户
    selectOpen(type) {
      this.show = type
      this.$refs.select.show();
    },
    //获取用户
    selectUser(userId, userName, phone) {
      if (this.show === '1') {
        this.$set(this.formResume, 'operateName', userName)
        this.$set(this.formResume, 'operateId', userId)
      } else if (this.show === '2') {
        this.$set(this.formResume, 'createName', userName)
        this.$set(this.formResume, 'createId', userId)
      } else if (this.show === '3') {
        this.$set(this.formResume, 'approveName', userName)
        this.$set(this.formResume, 'approveId', userId)
      }
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },
    //确认按钮，关闭第二层，并且获取到指定的数据
    getEnter() {
      this.innerVisible = false;
      //拼接id,赋值给外协id，传入后端
      if (this.enterId.length === 1 && this.enterName.length === 1) {
        this.form.enterpriseId = this.enterId[0];
        this.form.enters = this.enterName[0];
      } else {
        this.form.enterpriseId = this.enterId.join(',');
        this.form.enters = this.enterName.join(',');
      }
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.classificationId = null
      this.queryParams.productStatus = null
      this.queryParams.productName = null
      this.queryParams.productType = null
      this.queryParams.productNo = null
      this.queryParams.examineStatus = null
      this.queryParams.organizationName = null
      this.reset();
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.examineList = selection.map(item => item.examineStatus)
      this.productStatusList=selection.map(item=>item.productStatus)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    // 多选框选中数据
    handleSelectionChangeEnter(selection) {
      this.enterId = selection.map(item => item.enterpriseId)
      this.enterName = selection.map(item => item.enterpriseName)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 搜索按钮操作 */
    handleQueryEnter() {
      this.queryParams.pageNum = 1;
      this.getListEnter();
    },
    //企业重置
    resetQueryEnter() {
      this.resetForm("queryFormEnter");
      this.handleQueryEnter();
    },

    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.title = "添加资质产品管理";
      this.form.exeStandard = new Date().getTime();
      this.form.template = new Date().getTime() + 20;
      this.form.productManual=new Date().getTime()+40;
      this.isChange = true;
      this.typeSelect = 0;
      this.addStatus = 1;
      this.form.isChange = 0;
      if (this.queryParams.classificationId != null) {
        this.form.classificationId = this.queryParams.classificationId;
      } else {
        this.form.classificationId = '650c44e1-b575-4b62-9d54-1ba9d1e8abb7';
      }
      this.form.userName = this.$store.state.user.name;
      this.form.creationTime = new Date();
      this.addSign = 0;
      this.isUpload = true;
      this.open = true;
    },
    getFile(data) {
      console.log(JSON.stringify(data))
    },
    //选择按钮
    handleChange() {
      this.changeOpen = true;
      this.isUpload = false;
    },
    /** 修改按钮操作 */
    handleUpdate(row, index) {
      this.reset();
      const id = row.id || this.ids
      getQualification(id).then(response => {
        this.form = response.data;
        console.log(this.form)
        this.addStatus = 2;
        this.isChange = true;
        this.addSign = 1;
        this.index = index + 1;
        this.typeSelect = 1;
        this.isUpload = true;
        this.open = true;
        this.title = "修改资质产品管理";
      });
    },
    //子传父
    changeProduct(data) {
      this.$refs.form.resetFields();
      const { template, exeStandard,productManual, ...rest } = data;
      this.form = { ...this.form, ...rest }; // 将剩余的字段合并到 this.form 中
      this.form.id = null;
      this.form.isChange = 1;
      this.changeOpen = false;
      // this.OnlyRead = true;
      this.typeSelect = 1;
      this.form.classificationId = '650c44e1-b575-4b62-9d54-1ba9d1e8abb7';
      this.isUpload = true;
    },
    //取消选择
    closeProduct() {
      this.$refs.form.resetFields();
      this.form = {};
      this.changeOpen = false;
      this.OnlyRead = false;
      this.typeSelect = 0;
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null && this.addStatus === 2) {
            queryFile(this.form.template, "qualification").then(res=>{
              var dataFile = res.data
              // if (dataFile.length == 0) {
              //   this.$modal.msgError("请上传样板！");
              // }else {
              //   updateQualification(this.form).then(response => {
              //    if (response.code===200){
              //      this.$modal.msgSuccess("修改成功");
              //      this.open = false;
              //      this.getList();
              //    }else {
              //      this.$modal.error(response.msg);
              //      this.open = false;
              //      this.getList();
              //    }
              //   });
              // }
              updateQualification(this.form).then(response => {
                if (response.code===200){
                  this.$modal.msgSuccess("修改成功");
                  this.open = false;
                  this.getList();
                }else {
                  this.$modal.error(response.msg);
                  this.open = false;
                  this.getList();
                }
              });
            })
          } else if (this.form.id != null && this.addStatus === 3) {
            examine(this.form).then(res => {
              this.$modal.msgSuccess("审核成功");
              this.open = false;
              this.getList();
            })
          }
          else {
            queryFile(this.form.template, "qualification").then(res=>{
              var dataFile = res.data
              // if (dataFile.length == 0) {
              //   this.$modal.msgError("请上传样板！");
              // }else {
              //
              // }
              addQualification(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.OnlyRead = false;
                this.isChange = false;
                this.getList();
              });
            })
          }
        }
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('qualificationInfo/qualification/export', {
        ...this.queryParams
      }, `qualification_${new Date().getTime()}.xlsx`)
    },
    handlePictureCardPreview(id, code) {
      this.uploadId = id;
      this.UploadCode = code;
      this.openFileList = true;
    },
    handlePictureCardPreviewResume(id) {
      this.uploadId = id;
      this.resumeFileList = true;
    },
    // 供应商产品对话框
    openSupplierDialog() {
      if (this.form.id !== null && this.OnlyRead) {
        return; // 如果是只读模式，不打开对话框
      }
      // 阻止输入框获得焦点，转而打开对话框
      document.activeElement.blur();
      this.openUser = true; // 保留原handleTextAreaFocus的功能
      this.supplierDialogVisible = true;
    },
    // 处理供应商产品选择
    handleSelectProduct(selectedProducts) {
      if (selectedProducts && selectedProducts.length > 0) {
        // 初始化空数组（如果不存在）
        if (!this.form.supplierProductList) {
          this.form.supplierProductList = [];
        }

        // 从选中产品中提取ID，用于去重
        const existingIds = this.form.supplierProductList.map(item => item.id);

        // 添加不重复的选中产品
        selectedProducts.forEach(product => {
          if (!existingIds.includes(product.id)) {
            this.form.supplierProductList.push({
              id: product.id,
              productName: product.productName,
              enterpriseName: product.enterpriseName
            });
          }
        });

        // 更新供应商产品ID字符串和文本（为了兼容）
        this.form.supplierProductId = this.form.supplierProductList.map(item => item.id).join(',');
        this.form.supplierProduct = this.form.supplierProductList.map(item => `${item.productName}（${item.enterpriseName}）`).join('，');
      }
      this.supplierDialogVisible = false;
    },
    // 移除供应商产品
    removeSupplierProduct(index) {
      this.form.supplierProductList.splice(index, 1);

      // 更新供应商产品ID字符串和文本（为了兼容）
      this.form.supplierProductId = this.form.supplierProductList.map(item => item.id).join(',');
      this.form.supplierProduct = this.form.supplierProductList.map(item => item.productName).join('，');
    },
    // 处理供应商产品对话框关闭
    handleSupplierDialogClose() {
      this.supplierDialogVisible = false;
    },
    // 确认选择产品
    confirmSelectProducts() {
      if (this.$refs.supplierQualification) {
        this.$refs.supplierQualification.submitSelectProducts();
      }
    }
  }
};
</script>
<style>
#inp {
  width: 202.5px;
}

.myTooltips {
  width: 50%;
}

.ellipsis-cell {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.red-text {
  color: red;
}
.manager-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;

  .manager-tag {
    padding: 0 12px;
    border: 1px solid #dcdfe6;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.3s;

    &:hover {
      border-color: #409eff;
      color: #409eff;
    }

    &.active {
      background-color: #409eff;
      border-color: #409eff;
      color: #fff;
    }
  }
}

.supplier-product-container {
  width: 100%;
  min-width: 500px;
}

.supplier-product-container .el-table {
  margin-bottom: 10px;
}
</style>
